package com.slh.touchandroid.utils;

import java.text.DecimalFormat;

import android.text.Editable;
import android.text.TextUtils;

public class TextUtil {
	public static boolean isEmailValid(Editable email) {
		if (TextUtils.isEmpty(email)) {
			return false;
		}
		return android.util.Patterns.EMAIL_ADDRESS.matcher(email.toString())
				.matches();
	}
	
	public static String getSizeString(long size) {
		if (size <= 0)
			return "0";
		final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
		int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
		return new DecimalFormat("#,##0.#").format(size
				/ Math.pow(1024, digitGroups))
				+ " " + units[digitGroups];

	}

}
